using System.Linq;
using UnityEditor;
using UnityEngine;

[CreateAssetMenu(menuName = "RPG Setup/Quest Data/Quest Data Base", fileName = "QUEST DATA BASE")]
public class QuestDataBaseSO : ScriptableObject
{
    public QuestDataSO[] allQuests;


    public QuestDataSO GetQuestById(string id) => allQuests.FirstOrDefault(target => target != null && target.questSaveId == id);

#if UNITY_EDITOR
    [ContextMenu("Collect All Quest")]
    public void CollectionAllQuest()
    {
        string[] guids = AssetDatabase.FindAssets("t:QuestDataSO");
        allQuests = guids
                    .Select(guid => AssetDatabase.LoadAssetAtPath<QuestDataSO>(AssetDatabase.GUIDToAssetPath(guid)))
                    .Where(quest => quest != null)
                    .ToArray();

        EditorUtility.SetDirty(this);
        AssetDatabase.SaveAssets();
    }   

    #endif
}
